package com.dbw.englishassistant.ui.tool;

import java.awt.Component;

import javax.swing.JOptionPane;

public class OptionPaneTool {

    private Component parentComponent = null;
    
    public OptionPaneTool(Component parentComponent) {
        this.parentComponent = parentComponent;
    }
    
    public void setParentComponent(Component parentComponent) {
        this.parentComponent = parentComponent;
    }
    
    public void showMessage(String message) {
        JOptionPane.showMessageDialog(parentComponent, message, "提示", 
                JOptionPane.INFORMATION_MESSAGE);
    }
    
    public void showError(String message) {
        JOptionPane.showMessageDialog(parentComponent, message, "错误提示", 
                JOptionPane.ERROR_MESSAGE);
    }
    
    public boolean askForConfirmation(String message) {
        String[] options = new String[]{"  是  ", "  否  "};
        int option = JOptionPane.showOptionDialog(
                parentComponent, message, "确认提示", JOptionPane.DEFAULT_OPTION, 
                JOptionPane.QUESTION_MESSAGE, 
                null, options, options[1]);
        
        return option == JOptionPane.YES_OPTION;
    }
}
